﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebshopPizzaRio
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        private PizzaBLL pbll = new PizzaBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            String s = Request.QueryString["Zoek"];
            

            if (s == null)
            {
                pizzaoverzichtLV.DataSource = pbll.getPizza();
                pizzaoverzichtLV.DataBind();

            }
            else
            {
                Label2.Text = "U zocht op: " + s;
                DropDownList1.Visible = false;
                Label2.Visible = true;
                pizzaoverzichtLV.DataSource = pbll.PizzaZoeken(s);
                pizzaoverzichtLV.DataBind();
            }

        }

        protected void pizzaoverzichtLV_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
        {
            pizzaoverzichtLV.SelectedIndex = e.NewSelectedIndex;

            ShoppingCart cart = (ShoppingCart)Session["shoppingcart"];

            Items newpizza = cart.getNewItem();
            newpizza.PizzaNaam = pizzaoverzichtLV.SelectedDataKey.Values["naam"].ToString();
            decimal pps = decimal.Parse(pizzaoverzichtLV.SelectedDataKey.Values["prijs"].ToString());
            newpizza.PrijsperStuk = pps;
            newpizza.Aantal = 1;
            newpizza.PizzaID = int.Parse(pizzaoverzichtLV.SelectedDataKey.Values["pizzaid"].ToString());
            cart.AddItem(newpizza);

            ListView listviewmp;
            listviewmp = (ListView)(Master).FindControl("ListView1");
            listviewmp.DataBind();

            Label label1mp;
            label1mp = (Label)(Master).FindControl("label1");
            label1mp.Text = "Totaal bedrag: € " + cart.getTotaalBedrag();
        }

        protected void pizzaoverzichtLV_PagePropertiesChanged(object sender, EventArgs e)
        {
            pizzaoverzichtLV.DataBind();
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedValue == "soortnaamAZ")
            {
                pizzaoverzichtLV.DataSource = pbll.sorterenopnaamAZ();
                pizzaoverzichtLV.DataBind();
            }
            else if (DropDownList1.SelectedValue == "soortnaamZA")
            {
                pizzaoverzichtLV.DataSource = pbll.sorterenopnaamZA();
                pizzaoverzichtLV.DataBind();
            }
            else if (DropDownList1.SelectedValue == "sortprijshoog")
            {
                pizzaoverzichtLV.DataSource = pbll.sorterenopprijshoog();
                pizzaoverzichtLV.DataBind();
            }
            else if (DropDownList1.SelectedValue == "sortprijslaag")
            {
                pizzaoverzichtLV.DataSource = pbll.sorterenopprijslaag();
                pizzaoverzichtLV.DataBind();
            }

            else if (DropDownList1.SelectedValue == "sortbestsellermeest")
            {
                pizzaoverzichtLV.DataSource = pbll.sorterenopbestsellermeest();
                pizzaoverzichtLV.DataBind();
            }

         }

    }
}